package GUI;

import CommonGui.Keys;
import CommonGui.KeysDigits;
import CommonGui.ManagePrinter;
import DataObjects.User;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Image;
import java.io.IOException;

import jpos.CashDrawer;
import jpos.POSPrinter;

/**
 * @author Andrey
 * @author Igor
 *
 */

public class MainMenu extends JFrame {

	private static final long serialVersionUID = 1L;
	private User user;
	public MainScreen ms=null;
	public Keys keyboard;
	public KeysDigits keyBoardDigits;
	public JPanel keyboardPanel;
	private POSPrinter jPos_Printer=null;
	private CashDrawer cashDrawer=null;
	private ManagePrinter managePrinter;

	/**
	 * This is the default constructor
	 *
	 */
	
	public MainMenu(MainScreen MS,User USER)  
	{
		super();
		
		/*
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
		
		
		
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (UnsupportedLookAndFeelException e) {
		    // handle exception
		} catch (ClassNotFoundException e) {
		    // handle exception
		} catch (InstantiationException e) {
		    // handle exception
		} catch (IllegalAccessException e) {
		    // handle exception
		}
		
		
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                          //sdelat kak logout
		this.ms = MS;
		this.user=USER;   
		initialize();
		getContentPane().setPreferredSize(getMaximumSize());
		
	}

	/**
	 * This method initializes the Main menu screen .
	 * 
	 * @return void
	 */
	private void initialize() 
	{
		
		
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		getContentPane().add(new PanelButtons(this), BorderLayout.NORTH);
		getContentPane().add(new PanelFunctionsEmpty(), BorderLayout.EAST);
		getContentPane().add(getCenterPanel(), BorderLayout.CENTER);
		//getContentPane().add(new PanelGeneralCenterPanel(this), BorderLayout.CENTER);
		getContentPane().add(getKeyboardPanel(), BorderLayout.SOUTH);
		this.setVisible(true);
	}
	
	
	
	private JPanel getCenterPanel()
	{
		JPanel centralPanel=new JPanel();
		centralPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		Icon logoIcon=new ImageIcon("logo-icon.png");
		Image img = ((ImageIcon) logoIcon).getImage();
		Image newimg = img.getScaledInstance(800, 400,java.awt.Image.SCALE_SMOOTH);
		logoIcon = new ImageIcon(newimg);
		JLabel logoLabel=new JLabel(logoIcon);
		centralPanel.add(logoLabel);
		
		return centralPanel;
		
		
	}
	
	private JPanel getKeyboardPanel()
	{
		keyboardPanel = new JPanel();
		keyboardPanel.setBackground(new Color(210, 180, 140));
		keyboardPanel.setVisible(false);
		keyboardPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 40,5 ));
		keyboard=new Keys();
		keyBoardDigits=new KeysDigits();
		keyboardPanel.add(keyboard);
		keyboardPanel.add(keyBoardDigits);		
		return keyboardPanel;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public POSPrinter getjPos_Printer() {
		return jPos_Printer;
	}

	public void setjPos_Printer(POSPrinter jPos_Printer) {
		this.jPos_Printer = jPos_Printer;
	}

	public CashDrawer getCashDrawer() {
		return cashDrawer;
	}

	public void setCashDrawer(CashDrawer cashDrawer) {
		this.cashDrawer = cashDrawer;
	}

	public ManagePrinter getManagePrinter() {
		return managePrinter;
	}

	public void setManagePrinter(ManagePrinter managePrinter) {
		this.managePrinter = managePrinter;
	}
	
	
	
}    
